﻿using System.Windows;
using System.Windows.Controls;

namespace Com.Lancetinc.Evs.Reports.RadPdf;

internal class TextBoxRenderer : UIElementRendererBase
{
    internal override bool Render(UIElement element, PdfRenderContext context)
    {
        var textBox = element as TextBox;
        if (textBox == null)
        {
            return false;
        }

        var text = textBox.Text;
        var foreground = textBox.Foreground;
        var width = textBox.ActualWidth;
        var height = textBox.ActualHeight;
        var fontFamily = textBox.FontFamily;
        var fontSize = textBox.FontSize;

        using (SaveClip(context.drawingSurface, new Rect(0, 0, textBox.ActualWidth, textBox.ActualHeight)))
        {
            TextRenderer.DrawTextBlock(text, context, foreground, width, height, fontFamily, fontSize);
        }

        return true;
    }
}